JavaScript で署名済みトランザクションを作成
code:example.js
const EthereumTx = require('ethereumjs-tx')
const EthereumUtil = require('ethereumjs-util')
// ADDRESS: 0x89c24a88BaD4abE0A4F5b2EB5a86db1fb323832C
const PRIVATE_KEY = '0x61ce8b95ca5fd6f55cd97ac60817777bdf64f1670e903758ce53efc32c3dffeb'
const txParams = {
nonce: 6,
gasPrice: 20000000000, // 20000000000
gasLimit: 21000, // 21000
to: '0x2890228D4478e2c3B0eBf5a38479E3396C1d6074',
value: '0x2386f26fc10000', // 0.01
data: null,
chainId: 3 // mainnet: 1, ropsten: 3
}
let tx = new EthereumTx(txParams)
let privateKeyBuffer = EthereumUtil.toBuffer(PRIVATE_KEY)
tx.sign(privateKeyBuffer)
let serializedTx = tx.serialize()
let signedTx = '0x' + serializedTx.toString('hex')
console.log(signedTx)
関連